package cn.zmall.manager.controller;

import cn.zmall.common.pojo.Result;
import cn.zmall.common.utils.ResultUtil;
import cn.zmall.manager.pojo.TbExpress;
import cn.zmall.manager.service.ExpressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author cxy
 * @Date 2020/11/13 15:43
 * @Version 1.0
 */
@RestController
@Api(value = "快递信息")
public class ExpressController {

    @Autowired
    private ExpressService expressService;


    @RequestMapping(value = "/getlistexpress",method = RequestMethod.GET)
    @ApiOperation(value = "查询快递信息")
    public Result<List<TbExpress>> getListExpress(){
        List<TbExpress> result = expressService.getListExpress();
        if(result == null){
            return new ResultUtil<List<TbExpress>>().setData(null);
        }
        return new ResultUtil<List<TbExpress>>().setData(result);
    }

    @RequestMapping(value = "/addexpress",method = RequestMethod.POST)
    @ApiOperation(value = "添加快递信息")
    public Result<Object> addExpress(@RequestBody TbExpress tbExpress){
        int result = expressService.addExpress(tbExpress);
        return new ResultUtil<Object>().setData(result);
    }


    @RequestMapping(value = "/delexpress",method = RequestMethod.DELETE)
    @ApiOperation(value = "删除快递信息")
    public Result<Object> delExpress(Integer expressId){
        int result = expressService.delExpress(expressId);
        return new ResultUtil<Object>().setData(result);
    }

    @RequestMapping(value = "/updateexpress",method = RequestMethod.POST)
    @ApiOperation(value = "更新快递信息")
    public Result<Object> updateExpress(@RequestBody TbExpress tbExpress){
        int result = expressService.updateExpress(tbExpress);
        return new ResultUtil<Object>().setData(result);
    }
}
